/* name: good
 * author: 5ab
 * created at: 2024-07-01
 */
#include <iostream>
#include <algorithm>
using namespace std;

#define all(x) (x).begin(), (x).end()
#define ssz(x) (int((x).size()))

auto chmax = [](auto& x, auto y) { if (x < y) x = y; };
auto chmin = [](auto& x, auto y) { if (y < x) x = y; };

using ll = long long;
const int N = 1e6, lgN = 20, S = 2 << lgN;

struct node
{
	int mn, mx, ans;
}
tr[S];
int a[N + 1];
char s[N + 1];

int ls(int x) { return x * 2; }
int rs(int x) { return x * 2 + 1; }

node merge(const node& lhs, const node& rhs) {
	return {
		min(lhs.mn, rhs.mn), max(lhs.mx, rhs.mx), max({ lhs.ans, rhs.ans, rhs.mx - lhs.mn })
	};
}

void build(int l, int r, int id)
{
	if (l == r)
		tr[id] = { min(a[l], a[l + 1]), max(a[l], a[l + 1]), 1 };
	else
	{
		int mid = (l + r) >> 1;
		build(l, mid, ls(id));
		build(mid + 1, r, rs(id));
		tr[id] = merge(tr[ls(id)], tr[rs(id)]);
	}
}

node query(int L, int R, int l, int r, int id)
{
	if (L <= l && r <= R)
		return tr[id];
	int mid = (l + r) >> 1; node ret = { N, -N, 0 };
	if (L <= mid)
		ret = merge(ret, query(L, R, l, mid, ls(id)));
	if (mid < R)
		ret = merge(ret, query(L, R, mid + 1, r, rs(id)));
	return ret;
}

signed main()
{
	freopen("good.in", "r", stdin);
	freopen("good.out", "w", stdout);
	
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
	
	int n, m;
	
	cin >> n >> m >> s;
	a[0] = 0;
	for (int i = 0; i < n; i++)
		a[i + 1] = a[i] + (s[i] == '1' ? 1 : -1);
	
	build(0, n - 1, 1);
	
	int x, y, ans = 0;
	while (m--)
	{
		cin >> x >> y, x--, y--;
		ans ^= query(x, y, 0, n - 1, 1).ans - (a[y + 1] - a[x]);
	}
	cout << ans << endl;
	
	return 0;
}
// started coding at: 07-01 08:59:28